<template>
  <Dialog v-model="dialogVisible" :title="dialogTitle" width="1200">
  <ContentWrap>
    <!-- 搜索工作栏 -->
    <el-form
      class="-mb-15px"
      :model="queryParams"
      ref="queryFormRef"
      :inline="true"
      label-width="68px"
    >
      <el-form-item label="">
        <label>{{ equipName }}（{{ queryParams.devSn }}）</label>
      </el-form-item>
      <el-form-item label="">
        <el-button type="primary" @click="remoteOpen()">远程开门</el-button>
      </el-form-item>
    </el-form>
  </ContentWrap>

  <!-- 列表 -->
  <ContentWrap>
    <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
      <el-table-column label="主键" align="center" prop="id" />
      <el-table-column label="系统" align="center" prop="sysCode" width="70"/>
      <el-table-column label="社区名称" align="center" prop="communityName" width="100"/>
      <el-table-column label="设备MAC" align="center" prop="devSn" width="100"/>
      <el-table-column label="设备名称" align="center" prop="devName" width="120"/>
      <el-table-column label="租户ID" align="center" prop="empId" width="80"/>
      <el-table-column label="租户手机号" align="center" prop="empPhone" width="120"/>
      <el-table-column label="租户姓名" align="center" prop="empName" width="120"/>
      <el-table-column label="卡号" align="center" prop="empCardNo" width="120"/>
      <el-table-column label="抓拍图片地址" align="center" prop="captureImageUrl" />
      <el-table-column label="人脸识别" align="center" >
        <el-table-column label="年龄" align="center" prop="faceAge" width="60"/>
        <el-table-column label="性别" align="center" prop="faceGender" width="60"/>
        <el-table-column label="比对" align="center" prop="faceMatchScore" width="60"/>
        <el-table-column label="体温" align="center" prop="bodyTemperature" width="60"/>
      </el-table-column>
      <el-table-column label="密码或二维码" align="center" prop="number" width="100"/>
      <el-table-column label="推送事件种类" align="center" prop="eventKinds" width="120"/>
      <el-table-column label="记录时间" align="center" prop="eventTime" width="120"/>
      <el-table-column label="事件类型 " align="center" prop="eventType" width="100"/>
    </el-table>
    <!-- 分页 -->
    <Pagination
      :total="total"
      v-model:page="queryParams.pageNo"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </ContentWrap>
  </Dialog>
</template>

<script setup lang="ts">
import { OpenRecordApi, OpenRecordVO } from '@/api/zwsj/openrecord'
/** 开门日志 列表 */
defineOptions({ name: 'OperDoorControl' })


const dialogVisible = ref(false) // 弹窗的是否展示
const dialogTitle = ref('') // 弹窗的标题

const message = useMessage() // 消息弹窗
const { t } = useI18n() // 国际化

const loading = ref(true) // 列表的加载中
const list = ref<OpenRecordVO[]>([]) // 列表的数据
// 列表的总页数
const total = ref(0)

const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  id: undefined,
  sysCode: undefined,
  communityId: undefined,
  communityName: undefined,
  devSn: '',
  devName: '',
  empPhone: '',
  empName: '',
  eventKinds: undefined,
})

const equipName = ref('')
const doorControlId = ref()
const open = async (id: number,equipMac: string,equipNameT : string) => {
  dialogVisible.value = true
  queryParams.devSn = equipMac
  equipName.value = equipNameT
  doorControlId.value = id
  getList();
}
defineExpose({ open }) // 提供 open 方法，用于打开弹窗


/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await OpenRecordApi.getOpenRecordPage(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

/** 搜索按钮操作 */
const remoteOpen = async () => {
  let data = await  OpenRecordApi.remoteOpenOfXimo({
    "roleCode": "99",///系统内置人员99
    "equipId": doorControlId.value
  })
  if(true == data){
    message.success(t('common.success'));
    queryParams.pageNo = 1
    getList()
  }
}
</script>